/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/04/15
\**********************/
#include "LuaActiveX.h"

#define CObjPtr ((CActiveXUI*)m_cobj)

namespace DuiLib {

int /*HWND*/ LuaActiveX::GetHostWindow()
{
    return (int)CObjPtr->GetHostWindow();
}

bool LuaActiveX::IsDelayCreate()
{
    return CObjPtr->IsDelayCreate();
}

void LuaActiveX::SetDelayCreate(bool bDelayCreate)
{
    CObjPtr->SetDelayCreate(bDelayCreate);
}

bool LuaActiveX::IsMFC()
{
    return CObjPtr->IsMFC();
}

void LuaActiveX::SetMFC(bool bMFC)
{
    CObjPtr->SetMFC(bMFC);
}

int LuaActiveX::CreateControl(LuaState *L)
{
    LuaStack args(L);
    SDTString pstrCLSID = LuaHelperNS::GetTString(args[2]);
    bool bRet = CObjPtr->CreateControl(pstrCLSID.c_str());
    L->PushBoolean(bRet);
    return 1;
}

int LuaActiveX::GetModuleName(LuaState *L)
{
    SDTString str = CObjPtr->GetModuleName().GetData();
    LuaHelperNS::PushTString(L, str);
    return 1;
}

int LuaActiveX::SetModuleName(LuaState *L)
{
    LuaStack args(L);
    SDTString str = LuaHelperNS::GetTString(args[2]);
    CObjPtr->SetModuleName(str.c_str());
    return 0;
}

void LuaActiveX::SetVisible(bool bVisible)
{
    CObjPtr->SetVisible(bVisible);
}

void LuaActiveX::SetInternVisible(bool bVisible)
{
    CObjPtr->SetInternVisible(bVisible);
}

int LuaActiveX::SetPos(LuaState *L)
{
    LuaStack args(L);
    RECT rc = LuaHelperNS::GetRect(args[2]);
    bool bNeedInvalidate = LuaHelperNS::GetBool(args[3], true);
    CObjPtr->SetPos(rc, bNeedInvalidate);
    return 0;
}

int LuaActiveX::Move(LuaState *L)
{
    LuaStack args(L);
    SIZE sz = LuaHelperNS::GetSize(args[2]);
    bool bNeedInvalidate = LuaHelperNS::GetBool(args[3], true);
    CObjPtr->Move(sz, bNeedInvalidate);
    return 0;
}

SDLUA_BEGIN_REGISTER(LuaActiveX, ActiveX, Control)
    SDLUA_REGISTER_FUN_CPP(LuaActiveX, GetHostWindow, GetHostWindow)

    SDLUA_REGISTER_FUN_CPP(LuaActiveX, IsDelayCreate, IsDelayCreate)
    SDLUA_REGISTER_FUN_CPP(LuaActiveX, SetDelayCreate, SetDelayCreate)
    SDLUA_REGISTER_FUN_CPP(LuaActiveX, IsMFC, IsMFC)
    SDLUA_REGISTER_FUN_CPP(LuaActiveX, SetMFC, SetMFC)

    SDLUA_REGISTER_FUN_LUA(LuaActiveX, CreateControl, CreateControl)

    SDLUA_REGISTER_FUN_LUA(LuaActiveX, GetModuleName, GetModuleName)
    SDLUA_REGISTER_FUN_LUA(LuaActiveX, SetModuleName, SetModuleName)
    
    SDLUA_REGISTER_FUN_CPP(LuaActiveX, SetVisible, SetVisible)
    SDLUA_REGISTER_FUN_CPP(LuaActiveX, SetInternVisible, SetInternVisible)

    SDLUA_REGISTER_FUN_LUA(LuaActiveX, SetPos, SetPos)
    SDLUA_REGISTER_FUN_LUA(LuaActiveX, Move, Move)

SDLUA_END_REGISTER

SDLUA_BEGIN_UNREGISTER(LuaActiveX, ActiveX)
SDLUA_END_UNREGISTER(ActiveX)

}

#undef CObjPtr